﻿using System;

namespace CSharp_1209.AbstractClass
{
    public class SavingsAccount : Account
    {
        private float _minBalance;
        private float _bankCharge;
        public bool Flag = true;

        public bool AcceptDetails()
        {
            double amount;

            Console.Write("Enter the customer name: ");
            string name = Console.ReadLine();

            // refactor -> sửa code lại nhưng chức năng ko thay đổi
            long number;
            do
            {
                Console.Write("Enter the account number: ");
                number = Convert.ToInt64(Console.ReadLine());

                if (number <= 0)
                {
                    Console.WriteLine("Invalid Account Number");
                }
                else
                {
                    SetDetails(name, number);
                }
            } while (number <= 0);

            Console.WriteLine("\nInitial balance available: " + Balance + "\n\n");

            Console.WriteLine("Select the type of transaction: ");
            Console.WriteLine(" 1. Withdraw \n 2. Deposit");
            Console.Write("Select your choice : ");

            int choice = Convert.ToInt32(Console.ReadLine());

            switch (choice)
            {
                case 1:
                    Console.WriteLine("Minimum balance to be maintained: " + _minBalance + " $\n");
                    Console.Write("Enter the amount to be withdrawn: ");

                    amount = Convert.ToDouble(Console.ReadLine());
                    Withdraw(amount);
                    break;
                case 2:
                    Console.Write("Enter the amount to be deposited: ");

                    amount = Convert.ToDouble(Console.ReadLine());
                    Deposit(amount);
                    break;
                default:
                    Console.WriteLine("Invalid Choice");
                    return false;
            }

            if (!Flag)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        protected override void SetDetails(string name, long number)
        {
            base.SetDetails(name, number);
            _minBalance = 500;
        }

        protected override double BankCharges(double amount)
        {
            _bankCharge = (float)(amount * (3 / 100));
            return _bankCharge; // 3% số tiền được rút
        }

        protected override void Deposit(double amount)
        {
            if (amount > 0)
                base.Deposit(amount);
            else
                Console.WriteLine("You must not deposit negative amount");

        }

        protected override void Withdraw(double amount)
        {
            // amount = -100 , Balance = 500, minBalance = 500
            if (amount <= Balance - _minBalance - Math.Round(_bankCharge) && amount >= 0)
            {
                base.Withdraw(amount);
            }
            else
            {
                Console.WriteLine("You do not have sufficient balance in your account");
                Flag = false;
            }
        }

        public override void Display()
        {
            base.Display();
        }
    }
}
